package home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.android.volley.Response;
import com.google.gson.Gson;

import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import base.BasePage;
import bean.News;
import httptool.QLParser;
import httptool.getHttpUrl;
import httptool.takeUrlResource;
import news.fragment.MenuFragment2;
import shanshuitiancheng.news.MainActivity;

/**
 * Created by cch on 2016/6/14.
 */
public class NewsCenterPage extends BasePage {
    public NewsCenterPage(Context ct){
        super(ct);
    }

    @Override
    public View initView(LayoutInflater inflater) {
        TextView textView = new TextView(ct);
        textView.setText("我是新聞中心");
        return textView;
    }

    @Override
    public void initData() {
        TestGet();
    }
    private List<String> menuNewCenterList = new ArrayList<String>();
    private void TestGet() {
    takeUrlResource.getJson(ct,getHttpUrl.index, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            News data = QLParser.parse(s, News.class);//s 为所传参数，news.class为你存放json数据的类
            List<News.NewsBean> news = data.getNews();//获取json里面的hot数据
            for (News.NewsBean hb:news){
              menuNewCenterList.add(hb.getTitle());
            }
            MenuFragment2 menuFragment2 = ((MainActivity)ct).getMenuFragment();
            menuFragment2.initMenu(menuNewCenterList);
        }
    });
    }
}
